import { create } from "zustand";
import { ConfigService } from "../../core/services/config_service";
import { ModelInfo } from "../../core/types/ollama";

export interface ModelInfoModalInterface {
    isOpen: boolean;
    toggle: () => void;
    modelInfo: ModelInfo | null;
    setModelInfo: (modelInfo: ModelInfo) => void;
    isLoading: boolean;
    setIsLoading: (isLoading: boolean) => void;
    error: string | null;
    setError: (error: string | null) => void;
    open: (modelName: string) => void;
}

export const useModelInfo = create<ModelInfoModalInterface>((set) => ({
    isOpen: false,
    toggle: () => set((state) => ({ isOpen: !state.isOpen })),
    modelInfo: null,
    setModelInfo: (modelInfo: ModelInfo) => set({ modelInfo }),
    isLoading: false,
    setIsLoading: (isLoading: boolean) => set({ isLoading }),
    error: null,
    setError: (error: string | null) => set({ error }),
    open: async (modelName: string) => {
        set({ isLoading: true, error: null });
        const configService = ConfigService.getInstance();
        const modelInfo = await configService.getModelInfo(modelName);
        set({ modelInfo, isLoading: false, isOpen: true, error: null });
    },
}));
